﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YXChatFormClient.Utility;

namespace YXChatFormClient
{
    public partial class FrmIndex : Form
    {
        public FrmIndex()
        {
            InitializeComponent();
        }

        #region 聊天按钮
        private void picChat_MouseMove(object sender, MouseEventArgs e)
        {
            picChat.ImageLocation = ImageHelper.GetStaticImage("chat_active.png");
        }

        private void picChat_MouseLeave(object sender, EventArgs e)
        {
            picChat.ImageLocation = ImageHelper.GetStaticImage("chat.png");
        }
        #endregion

        #region 好友按钮
        private void picPeople_MouseMove(object sender, MouseEventArgs e)
        {
            picPeople.ImageLocation = ImageHelper.GetStaticImage("people_active.png");
        }

        private void picPeople_MouseLeave(object sender, EventArgs e)
        {
            picPeople.ImageLocation = ImageHelper.GetStaticImage("people.png");
        }
        #endregion

        #region 关闭按钮
        private void picClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void picClose_MouseMove(object sender, MouseEventArgs e)
        {
            picClose.BackColor = Color.FromArgb(250, 81, 81);
            picClose.ImageLocation = ImageHelper.GetStaticImage("close_active.png");
        }

        private void picClose_MouseLeave(object sender, EventArgs e)
        {
            picClose.BackColor = Color.White;
            picClose.ImageLocation = ImageHelper.GetStaticImage("close.png");
        }


        #endregion

        #region Panel重绘
        private void panelMenu_Paint(object sender, PaintEventArgs e)
        {
            PaintPanel(e, panelMenu.ClientRectangle, Color.White,
                Color.White, Color.FromArgb(214, 214, 214), Color.White);
        }

        /// <summary>
        /// 重绘panel
        /// </summary>
        /// <param name="e"></param>
        /// <param name="rectangle"></param>
        /// <param name="leftColor"></param>
        /// <param name="topColor"></param>
        /// <param name="rightColor"></param>
        /// <param name="bottomColor"></param>
        private void PaintPanel(PaintEventArgs e, Rectangle rectangle, Color leftColor, Color topColor, Color rightColor, Color bottomColor)
        {
            ControlPaint.DrawBorder(e.Graphics, rectangle,
                leftColor, 1, ButtonBorderStyle.Solid, //左边
                topColor, 1, ButtonBorderStyle.Solid, //上边
                rightColor, 1, ButtonBorderStyle.Solid, //右边
                bottomColor, 1, ButtonBorderStyle.Solid);//底边
        }

        private void panelConentHeader_Paint(object sender, PaintEventArgs e)
        {
            PaintPanel(e, panelConentHeader.ClientRectangle, Color.White,
                Color.White, Color.White, Color.FromArgb(214, 214, 214));
        }

        private void panelSearch_Paint(object sender, PaintEventArgs e)
        {
            PaintPanel(e, panelSearch.ClientRectangle, Color.White,
                Color.White, Color.FromArgb(214, 214, 214), Color.White);
        }
        #endregion

        private void picMaximize_Click(object sender, EventArgs e)
        {
            this.WindowState = this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal;
        }
        private void picMaximize_MouseLeave(object sender, EventArgs e)
        {
            picMaximize.BackColor = Color.White;
        }
        private void picMaximize_MouseMove(object sender, MouseEventArgs e)
        {
            picMaximize.BackColor = Color.FromArgb(229, 229, 229);

        }

        #region 最小化按钮

        private void picMinimize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void picMinimize_MouseMove(object sender, MouseEventArgs e)
        {
            picMinimize.BackColor = Color.FromArgb(229, 229, 229);
        }

        private void picMinimize_MouseLeave(object sender, EventArgs e)
        {
            picMinimize.BackColor = Color.White;
        }


        #endregion

        #region Common
        [DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
        private static extern void ReleaseCapture();

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        private static extern void SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);


        #endregion

        /// <summary>
        /// 头部拖动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panelConentHeader_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }

        private void picSearchClose_MouseMove(object sender, MouseEventArgs e)
        {
            this.picSearchClose.ImageLocation = ImageHelper.GetStaticImage("closeSearch_active.png");
        }

        private void picSearchClose_MouseLeave(object sender, EventArgs e)
        {
            this.picSearchClose.ImageLocation = ImageHelper.GetStaticImage("closeSearch.png");
        }
    }
}
